package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.RightsMapper;
import com.jt.pojo.Rights;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RightsServiceImpl implements RightsService{
    @Autowired
    private RightsMapper rightsMapper;

    @Override
    public List<Rights> findAll() {
        return rightsMapper.selectList(null);
    }

    @Override
    public List<Rights> getRightsList() {
        QueryWrapper<Rights> Wrapper = new QueryWrapper<>();
        Wrapper.eq("parent_id", 0);
        List<Rights> oneList = rightsMapper.selectList(Wrapper);
        for(Rights oneRights :oneList){
            Wrapper.clear();
            Wrapper.eq("parent_id", oneRights.getId());
            List<Rights> twoList = rightsMapper.selectList(Wrapper);
            oneRights.setChildren(twoList);
        }
        return oneList;
    }
}
